'use strict';

angular.module('com.dcos.app').controller('LayoutHeaderController', function LayoutHeaderController($rootScope, $window,$state, $uibModal, $cookies, dialog, LoginService) {
  var vm = this;
  var token = $cookies.getObject('token');
  vm.currentUser = $window.sessionStorage.getItem("curUserName");

  vm.navbarStatus=true;

  // 刷新页面，保持导航栏伸缩状态
  if (sessionStorage.getItem('navbarStatus') === 'narrow') {
    $(".navbar").addClass("narrow");
    $(".main-wrapper").addClass("narrow");
  }
  vm.project_id=$window.sessionStorage.getItem("curProjectId");
  vm.projectList=angular.fromJson($window.sessionStorage.getItem("projectList"));
  vm.fnchangeProject = function(project_id) {
    $window.sessionStorage.setItem("curProjectId",project_id);
    $state.go('app.dashboard', {}, { reload: true });
  }
  // 点击伸缩导航栏
  vm.slideNavbar=function(){
    /*
    var navbarStatus = sessionStorage.getItem('navbarStatus');
    if (!navbarStatus || navbarStatus === 'normal') {
      sessionStorage.setItem('navbarStatus', 'narrow');
      $(".navbar").addClass("narrow");
      $(".navbar-items").find("ul").hide()
      $(".main-wrapper").addClass("narrow");
    } else {
      sessionStorage.setItem('navbarStatus', 'normal');
      $(".navbar").removeClass("narrow");
      $(".navbar-items").find("ul").show()
      $(".main-wrapper").removeClass("narrow");
    }
    */
    vm.navbarStatus=!vm.navbarStatus;
    if(vm.navbarStatus){
      $(".navbar").addClass("narrow");
      $(".navbar-items").find("ul").hide()
      $(".main-wrapper").addClass("narrow");
      $(".navbar-logo").hide();
    }
    else{
      $(".navbar").removeClass("narrow");
      $(".navbar-items").find("ul").show()
      $(".main-wrapper").removeClass("narrow");
      $(".navbar-logo").show();
    }
  }

  vm.logout = function () {
      $window.sessionStorage.clear();
      $state.go("login");
  };

  vm.editUser = function(){
    var modalInstance = $uibModal.open({
      animation: true,
      templateUrl: 'controllers/login/edit-password/editPassword.html',
      controller: 'EditPasswordController',
      controllerAs: 'vm',
      backdrop: 'static',
      size: 'md'
    });
  }

});
